﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CompilerDLL.LexicalAnalysis;
using System.Collections;

namespace CompilerPrinciples.SyntaxAnalysis.Top_Down_Analysis
{
    public partial class LL1_Analysis :SyntaxAnalysis.BaseSyntax
    {
        

        #region 构造方法
        public LL1_Analysis()
        {
            InitializeComponent();

            ArrayList arrayHeaders = new ArrayList();
            arrayHeaders.Add("步骤");
            arrayHeaders.Add("符号栈");
            arrayHeaders.Add("输入串");
            arrayHeaders.Add("所用产生式");
            this.InitDataGridView(arrayHeaders);
        }
        #endregion 

        #region 覆盖父类的方法

        #region 添加到DataGridView
        /// <summary>
        /// 按行添加LL1的分析结果
        /// </summary>
        /// <param name="model_ll1_StepStatus"></param>
        protected override void Add_2DataGridView_Row(
            ArrayList arraySyntaxAnalysisSteps,
            int currentStep)
        {
            CompilerDLL.SyntaxAnalysis.Top_Down_Analysis.Model_LL1_StepStatus model_ll1_StepStatus =
                (CompilerDLL.SyntaxAnalysis.Top_Down_Analysis.Model_LL1_StepStatus)arraySyntaxAnalysisSteps[currentStep];
            string[] dr ={model_ll1_StepStatus.IntStep.ToString(),
                              model_ll1_StepStatus.StrStackProcSymbols,
                              model_ll1_StepStatus.StrCurrentTokens,
                              model_ll1_StepStatus.StrCurrentProduction};

            this.dataGridView1.Rows.Add(dr);
        }
        #endregion

        #endregion 

        #region button事件

        #region  进行LL（1）语法分析
        /// <summary>
        /// 进行LL（1）语法分析
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSyntaxAnalysis_Click(object sender, EventArgs e)
        {
            CompilerDLL.SyntaxAnalysis.Top_Down_Analysis.LL1_Analysis ll1 =
                new CompilerDLL.SyntaxAnalysis.Top_Down_Analysis.LL1_Analysis();

            DlgForcastAnalysisTable dlg=new DlgForcastAnalysisTable();

            this.DoSyntaxParse(ll1, dlg,"0");
        }
        #endregion 

        #region 构造预测分析表
        /// <summary>
        /// 构造预测分析表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGrammar_Click(object sender, EventArgs e)
        {

            DlgForcastAnalysisTable dlg = new DlgForcastAnalysisTable();
            dlg.ShowDialog();
        }
       
        #endregion

        #endregion

    }
}
